import request from '@/utils/request'

const commonApi = {
  checkCp: '/qw/qwAuth/checkCp',
  getQwBindUrl: '/qw/qwAuth/authUrl',
  getMpBindUrl: '/rwb/wxOpen/api/auth/get_auth_url',
  bindQywx: '/qw/qwAuth/bind',
  active: '/qw/qwMember/active',
  qwMemberPage: '/qw/qwMember/page',
  checkRunningSyncTask: '/qw/qwMember/checkRunningSyncTask',
  syncMembers: '/qw/qwMember/syncMembers',

  listMyMps: '/qw/mp/list',
  listActive: 'qw/qwMember/listActive',
  changeStatus: '/qw/gameTask/changeStatus',
  pageMyGame: '/qw/gameTask/search',
  deleteGame: '/qw/gameTask/remove',
  copyGame: '/qw/gameTask/copyGame',
  saveGame: '/qw/gameTask/save',
  getById: '/qw/gameTask/getById',
  listGameActive: 'qw/gameTask/listGameActive'

}

/**
 * 登陆 oauth2 密码模式
 * http://localhost:8070/sj/oauth/token?username=x&password=123456&grant_type=password&scope=server&client_id=ui&client_secret=metrix
 * @param username
 * @param password
 * @param client 登陆客户端
 * @param type 登陆类型 AuthenticationType
 */
export function login ({ username, password, client, type, params }) {
  return request({
    url: `/oauth/token?grant_type=password&scope=${type || 'DEFAULT'}&client_id=${client || 'XB'}&client_secret=metrix`,
    method: 'GET',
    params: {
      username,
      password,
      ...params
    },
    hideError: true
  })
}

export function getOrder (parameter) {
  return request({
    url: commonApi.getOrder,
    method: 'get',
    params: parameter
  })
}

export function qwMemberPage (parameter) {
  return request({
    url: commonApi.qwMemberPage,
    method: 'get',
    params: parameter
  })
}

export function getMpBindUrl (parameter) {
  return request({
    url: commonApi.getMpBindUrl,
    method: 'get',
    params: parameter
  })
}

export function getQwBindUrl (parameter) {
  return request({
    url: commonApi.getQwBindUrl,
    method: 'get',
    params: parameter
  })
}

export function listGameActive (parameter) {
    return request({
        url: commonApi.listGameActive,
        method: 'get',
        params: parameter
    })
}

export function checkCp (parameter) {
  return request({
    url: commonApi.checkCp,
    method: 'get',
    params: parameter
  })
}

export function bindQywx (parameter) {
  return request({
    url: commonApi.bindQywx,
    method: 'get',
    hideError: true,
    params: parameter
  })
}

export function active (parameter) {
  return request({
    url: commonApi.active,
    method: 'get',
    hideError: true,
    params: parameter
  })
}

export function checkRunningSyncTask (parameter) {
  return request({
    url: commonApi.checkRunningSyncTask,
    method: 'get',
    params: parameter
  })
}

/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function syncMembers (parameter) {
  return request({
    url: commonApi.syncMembers,
    method: 'get',
    params: parameter
  })
}

export function listMyMps (parameter) {
  return request({
    url: commonApi.listMyMps,
    method: 'get',
    params: parameter
  })
}

export function listActive (parameter) {
  return request({
    url: commonApi.listActive,
    method: 'get',
    params: parameter
  })
}

export function changeStatus (parameter) {
  return request({
    url: commonApi.changeStatus,
    method: 'get',
    params: parameter
  })
}

export function pageMyGame (parameter) {
  return request({
    url: commonApi.pageMyGame,
    method: 'get',
    params: parameter
  })
}

export function deleteGame (parameter) {
  return request({
    url: commonApi.deleteGame,
    method: 'get',
    params: parameter
  })
}

export function copyGame (parameter) {
  return request({
    url: commonApi.copyGame,
    method: 'get',
    params: parameter
  })
}

export function getById (parameter) {
  return request({
    url: commonApi.getById,
    method: 'get',
    params: parameter
  })
}

export function saveGame (parameter) {
  return request({
    url: commonApi.saveGame,
    method: 'POST',
    data: parameter
  })
}

export default {
  qwMemberPage,
  copyGame,
  deleteGame,
  pageMyGame,
  listMyMps,
  changeStatus,
  saveGame,
  getById,
  listActive,
  getMpBindUrl,
  getQwBindUrl,
  getOrder,
  login,
    listGameActive

}
